home *** CD-ROM | disk | FTP | other *** search
- /* -----------------------------------------------------------------
- File: alias.c
- XFCN to do 7.0 Alias stuff
-
- Version: see kVersionStr below
-
- History: 11-06-90 1.0d1 JRP from volCheck.c
- 11-12-90 1.0d2 JRP put version stuff in vers.h
- 11-13-90 1.0d3 JRP add trap and gestalt checking
- 11-16-90 1.0d4 JRP add findStrResId
- revise cmpStrtoResNum params
- revise returnMsgNum params
- 03-21-91 1.1d1 JRP add complete return for GetAliasInfo
- 03-22-91 1.1d2 JRP return GetAliasInfo as return-delimited
- 04-09-93 1.2 JRP fix bogus Gestalt call in Trap.c.
- 04-14-93 1.3 JRP add ResolveAliasToPath
-
- Author: John R. Powers, III
- Instructional Products Department
- Apple Computer, Inc.
- AppleLink: JohnPowers
-
- Copyright: see vers.h and "copyright" below.
-
- Computer: Mac Quadra 950 with System 7.1
-
- Compiler: MPW v3.2
-
- Usage:
-
-
- Requires HyperCard version 1.2 or better.
-
- Files:
-
- alias.c This source file
- alias.r Rez source
- vers.h header with version information
- trap.c source with trap functions
- trap.pro prototypes for trap.c
- makefileAlias make file
- aliasLab HyperCard stack for testing
-
- Full Build:
-
- see makefileAlias
-
-
- ----------------------------------------------------------------- */
-
- #include <HyperXCmd.h>
- #include <Types.h>
- #include <CType.h>
- #include <String.h> // strcpy…
- #include <Strings.h> // c2pstr…
- #include <PLStringFuncs.h> // PLstrcpy…
- #include <Memory.h>
- #include <ToolUtils.h>
- #include <Resources.h>
- #include <Packages.h>
- #include <Files.h>
- #include <Errors.h>
-
- #include <Aliases.h>
-
- /*
- Constants
- */
-
- #define kCterm '\0'
- #define kColon ':'
- #define kReturn '\n'
- #define kComma ','
- #define kSpace ','
- #define kCommaStr ","
- #define kReturnStr "\n"
- #define kColonStr ":"
- #define kSpaceStr " "
- #define kNoStringResource "Err 00 Missing STR# for "
- #define kNoErrNum 0 /* don't want to return an error code */
-
- #include "vers.h" /* version and copyright info */
-
- enum /* STR# indices */
- {
- ksCmdVersion=1, /* first of commands */
- ksCmdHelp,
- ksCmdMakeAlias,
- ksCmdResolveAlias,
- ksCmdVerifyAlias, /* phantom command for debugging only */
- ksCmdGetAliasInfo,
- ksCmdResolveAliasToPath,
- ksHelpDesc, /* help description */
- ksCallback, /* callback string for HyperCard */
- ksErrCommandWhere, /* first of error messages */
- ksErrCommandHuh, /* Err 02 */
- ksErrMissingParam, /* Err 03 */
- ksErrNoAliasMgr, /* Err 04 */
- ksErrEvalExpr, /* Err 05 */
- ksErrFSMakeFSSpec, /* Err 06 */
- ksErrNewAlias, /* Err 07 */
- ksErrResolveAlias, /* Err 08 */
- ksErrResolveAliasFile, /* Err 09 */
- ksErrGetAliasInfoZone, /* Err 10 */
- ksErrGetAliasInfoServer,/* Err 11 */
- ksErrGetAliasInfoVolume,/* Err 12 */
- ksErrGetAliasInfoParent /* Err 13 */
- };
-
- /*
- Prototypes
- */
-
- void addColon(Str255);
- void addStrItemToList(char *, char *);
- void addNumItemToList(char *, long);
- short cmpStrtoResNum(Str255, short, short);
- void convertDataToHexStr(char *, Handle);
- void convertFSSpecToStr(char *, FSSpecPtr);
- void convertHexStrToData(char *, Handle *);
- void convertStrToFSSpec(char *, FSSpecPtr);
- void copyPtoCstr(char *, Str255);
- Handle copyStrToHand(char *);
- void deleteColon(Str255);
- short equalPstr(Str255, Str255);
- short findStrResId(Str255);
- void getItemFromCList(char *, short, char *);
- void getItemFromPList(Str255, short, Str255);
- void handleToCstr(char *, Handle);
- void handleToPstr(Str255, Handle);
- void insertParent(char *, char *, char *);
- void pathNameFromFSSpec(Str255 pathName, FSSpec* fileSpec);
- void returnMsgNum(XCmdPtr, short, short, long);
-
- #include "trap.pro"
-
- /*
- Main program and entry point for XFCN.
- */
-
- pascal void entryPoint(paramPtr)
- /*
- */
-
- XCmdPtr paramPtr; /* the HyperCard connection */
- {
- char resultStr[1024],
- aliasStr[256],
- copyright[]=kCopyrightStr;
- Str255 command,
- resPstr,
- stackPathPstr;
- OSErr err;
- Handle hLongStackName;
- Ptr pLongStackName;
- FSSpec fileSpec;
- AliasHandle hAlias;
- Boolean bWasChanged,
- bResolveAliasChains,
- bTargetIsFolder,
- bWasAliased;
- short strResId;
-
- *resultStr = kCterm;
- if(paramPtr->paramCount<0)
- return; /* an event, ignore */
- /* find resource ID to use */
- /* for our string resource */
- strResId = findStrResId(kProgNameStr);
- if(!strResId)
- {
- strcpy(resultStr, kNoStringResource);
- strcat(resultStr, kProgNameStr);
- paramPtr->returnValue = copyStrToHand(resultStr);
- return;
- }
- /* check for command */
- if(paramPtr->paramCount==0)
- {
- returnMsgNum(paramPtr, ksErrCommandWhere, strResId, kNoErrNum);
- return;
- }
- handleToPstr(command, paramPtr->params[0]);
- /* version command? */
- if(cmpStrtoResNum(command, ksCmdVersion, strResId))
- {
- // Version
-
- strcpy(resultStr, kProgNameStr);
- strcat(resultStr, kSpaceStr);
- strcat(resultStr, kVersionStr);
- strcat(resultStr, kSpaceStr);
- strcat(resultStr, kAuthorStr);
- paramPtr->returnValue = copyStrToHand(resultStr);
- return;
- }
- /* help command? */
- else if(cmpStrtoResNum(command, ksCmdHelp, strResId))
- {
- // Help
-
- returnMsgNum(paramPtr, ksHelpDesc, strResId, kNoErrNum);
- return;
- }
- /* is there an alias manager? */
- else if(!aliasAvailable())
- {
- returnMsgNum(paramPtr, ksErrNoAliasMgr, strResId, kNoErrNum);
- return;
- }
- /* The following commands require the Alias Manager */
- if(cmpStrtoResNum(command, ksCmdMakeAlias, strResId))
- {
- // MakeAlias
- // Make an alias record.
-
- if(paramPtr->paramCount==2)
- handleToPstr(stackPathPstr, paramPtr->params[1]);
- else
- { /* path not given, use current stack */
- GetIndString(resPstr, strResId, ksCallback);
- hLongStackName = EvalExpr(paramPtr, resPstr);
- if(hLongStackName==nil || paramPtr->result==xresFail)
- {
- returnMsgNum(paramPtr, ksErrEvalExpr, strResId, kNoErrNum);
- return;
- }
- /* extract path name from long stack name */
- /* stack "<path to stack>" */
- HLock(hLongStackName);
- pLongStackName = *hLongStackName;
- while(*pLongStackName!='"' && *pLongStackName!=0)
- pLongStackName++;
- pLongStackName++;
- stackPathPstr[0] = 0;
- while(*pLongStackName!='"' && *pLongStackName!=0)
- stackPathPstr[++stackPathPstr[0]] = *pLongStackName++;
- DisposHandle(hLongStackName);
- }
- if(err = FSMakeFSSpec(0, 0L, stackPathPstr, &fileSpec))
- {
- addStrItemToList(resultStr, p2cstr(stackPathPstr));
- GetIndString(resPstr, strResId, ksErrFSMakeFSSpec);
- addStrItemToList(resultStr, p2cstr(resPstr));
- addNumItemToList(resultStr, err);
- paramPtr->returnValue = copyStrToHand(resultStr);
- return;
- }
- if(err = NewAlias(nil, &fileSpec, &hAlias))
- {
- returnMsgNum(paramPtr, ksErrNewAlias, strResId, err);
- return;
- }
- convertDataToHexStr(aliasStr, (Handle) hAlias);
- paramPtr->returnValue = copyStrToHand(aliasStr);
- DisposHandle((Handle) hAlias);
- return;
- }
- else if(cmpStrtoResNum(command, ksCmdResolveAlias, strResId))
- {
- // ResolveAlias
- // Resolve the alias and return the FSSpec for the file.
-
- if(paramPtr->paramCount<2)
- {
- returnMsgNum(paramPtr, ksErrMissingParam, strResId, err);
- return;
- }
- else
- {
- handleToCstr(aliasStr, paramPtr->params[1]);
- convertHexStrToData(aliasStr, &((Handle) hAlias));
- if(err = ResolveAlias(nil, hAlias, &fileSpec, &bWasChanged))
- {
- returnMsgNum(paramPtr, ksErrResolveAlias, strResId, err);
- DisposHandle((Handle) hAlias);
- return;
- }
- bResolveAliasChains = true;
- if(err = ResolveAliasFile(&fileSpec, bResolveAliasChains,
- &bTargetIsFolder, &bWasAliased))
- {
- returnMsgNum(paramPtr, ksErrResolveAliasFile, strResId, err);
- DisposHandle((Handle) hAlias);
- return;
- }
- convertFSSpecToStr(resultStr, &fileSpec);
- paramPtr->returnValue = copyStrToHand(resultStr);
- DisposHandle((Handle) hAlias);
- return;
- }
- }
- else if(cmpStrtoResNum(command, ksCmdVerifyAlias, strResId))
- {
- // VerifyAlias
- // This command is only used for debugging.
-
- if(paramPtr->paramCount<2)
- {
- returnMsgNum(paramPtr, ksErrMissingParam, strResId, err);
- return;
- }
- else
- {
- handleToCstr(aliasStr, paramPtr->params[1]);
- convertHexStrToData(aliasStr, &((Handle) hAlias));
- convertDataToHexStr(resultStr, (Handle) hAlias);
- paramPtr->returnValue = copyStrToHand(resultStr);
- DisposHandle((Handle) hAlias);
- return;
- }
- }
- else if(cmpStrtoResNum(command, ksCmdGetAliasInfo, strResId))
- {
- // GetAliasInfo
- // Return the information in the alias record
- // as a FSSpec string.
-
- if(paramPtr->paramCount<2)
- {
- returnMsgNum(paramPtr, ksErrMissingParam, strResId, err);
- return;
- }
- else
- {
- Str63 zonePstr,
- serverPstr,
- volumePstr,
- parentPstr;
- short index=0,
- notAtRoot=true;
- /*
- We return the alias information from left-to-right,
- zone-to-target, but build it from right to left.
- */
- handleToCstr(aliasStr, paramPtr->params[1]);
- convertHexStrToData(aliasStr, &((Handle) hAlias));
- *resultStr = 0;
- /*
- Build path from target up to root. Separate with colons.
- */
- while(notAtRoot)
- {
- if(err = GetAliasInfo(hAlias, index++, parentPstr))
- {
- returnMsgNum(paramPtr, ksErrGetAliasInfoParent, strResId, index-1);
- DisposHandle((Handle) hAlias);
- return;
- }
- else if(notAtRoot=(parentPstr[0]!=0))
- {
- if(index)
- insertParent(resultStr, p2cstr(parentPstr), kColonStr);
- else /* first (target) entry in path, no separator */
- strcpy(resultStr, p2cstr(parentPstr));
- }
- }
- /*
- Continue with volume and colon to complete path
- */
- if(err = GetAliasInfo(hAlias, asiVolumeName, volumePstr))
- {
- returnMsgNum(paramPtr, ksErrGetAliasInfoVolume, strResId, kNoErrNum);
- DisposHandle((Handle) hAlias);
- return;
- }
- insertParent(resultStr, p2cstr(volumePstr), kColonStr);
- /*
- Continue with server and comma
- */
- if(err = GetAliasInfo(hAlias, asiServerName, serverPstr))
- {
- returnMsgNum(paramPtr, ksErrGetAliasInfoServer, strResId, kNoErrNum);
- DisposHandle((Handle) hAlias);
- return;
- }
- insertParent(resultStr, p2cstr(serverPstr), kReturnStr);
- /*
- Finally zone and comma
- */
- if(err = GetAliasInfo(hAlias, asiZoneName, zonePstr))
- {
- returnMsgNum(paramPtr, ksErrGetAliasInfoZone, strResId, kNoErrNum);
- DisposHandle((Handle) hAlias);
- return;
- }
- insertParent(resultStr, p2cstr(zonePstr), kReturnStr);
- /*
- All done, return to caller
- */
- paramPtr->returnValue = copyStrToHand(resultStr);
- DisposHandle((Handle) hAlias);
- return;
- }
- }
- else if(cmpStrtoResNum(command, ksCmdResolveAliasToPath, strResId))
- {
- // GetResolvedPath
- // This is the same as ResolveAlias except that
- // we return a full path rather than a FSSpec.
-
- if(paramPtr->paramCount<2)
- {
- returnMsgNum(paramPtr, ksErrMissingParam, strResId, err);
- return;
- }
- else
- {
- handleToCstr(aliasStr, paramPtr->params[1]);
- convertHexStrToData(aliasStr, &((Handle) hAlias));
- if(err = ResolveAlias(nil, hAlias, &fileSpec, &bWasChanged))
- {
- returnMsgNum(paramPtr, ksErrResolveAlias, strResId, err);
- DisposHandle((Handle) hAlias);
- return;
- }
- bResolveAliasChains = true;
- if(err = ResolveAliasFile(&fileSpec, bResolveAliasChains,
- &bTargetIsFolder, &bWasAliased))
- {
- returnMsgNum(paramPtr, ksErrResolveAliasFile, strResId, err);
- DisposHandle((Handle) hAlias);
- return;
- }
- DisposHandle((Handle) hAlias);
- pathNameFromFSSpec(resultStr, &fileSpec);
- paramPtr->returnValue = copyStrToHand(p2cstr(resultStr));
- return;
- }
- }
- else
- {
- returnMsgNum(paramPtr, ksErrCommandHuh, strResId, kNoErrNum);
- return;
- }
- } /* -------------------------------------------- entryPoint */
-
- /*
- Functions
- */
-
- void addColon(volName)
- /*
- Add a colon to the end of volName.
- If one is already there, leave it.
- */
- Str255 volName;
- {
- if(volName[volName[0]]!=kColon)
- { /* add colon at end */
- volName[0]++;
- volName[volName[0]] = kColon;
- }
- } /* -------------------------------------------- addColon */
-
- void addNumItemToList(pList, num)
- /*
- Add num to pList.
-
- Preceed each item with a comma.
- The comma will not be added as
- the first item in a string or
- the first item in a line.
- */
- char *pList;
- long num;
- {
- Str255 tempPstr;
-
- NumToString(num, tempPstr);
- addStrItemToList(pList, p2cstr(tempPstr));
- } /* -------------------------------------------- addNumItemToList */
-
- void addStrItemToList(pList, pAdd)
- /*
- Add pAdd to pList.
-
- Preceed each item with a comma.
- The comma will not be added as
- the first item in a string or
- the first item in a line.
- */
- char *pList,
- *pAdd;
- {
- short len;
-
- if(len=strlen(pList))
- if(pList[len-1]!=kReturn)
- strcat(pList, kCommaStr);
- strcat(pList, pAdd);
- } /* -------------------------------------------- addStrItemToList */
-
- short cmpStrtoResNum(theString, theStrNum, strResId)
- /*
-
- 08/17/90 1.0a2 MJP new (GFXMenu)
- 11-16-90 1.0d4 JRP add strResId as parameter
- */
- Str255 theString;
- short theStrNum,
- strResId;
-
- {
- Str255 ResString;
-
- GetIndString(ResString, strResId, theStrNum);
- return (equalPstr(ResString, theString));
- } /* -------------------------------------------- cmpStrtoResNum */
-
- void convertDataToHexStr(hexStr, han)
- /*
- Convert the handle data to a string
- of ASCII hex characters.
- */
- char *hexStr;
- Handle han;
- {
- Ptr pData;
- long i;
- Size hanSize;
- Byte dataByte,
- byteValue,
- hiNibble,
- loNibble;
-
- hanSize = GetHandleSize(han);
- HLock(han);
- pData = *han;
- for(i=0; i<hanSize; i++)
- {
- dataByte = *pData++;
- byteValue = (dataByte & 0xF0) >> 4;
- if(byteValue>9)
- hiNibble = 'A' + (byteValue - 10);
- else
- hiNibble = '0' + byteValue;
- byteValue = dataByte & 0x0F;
- if(byteValue>9)
- loNibble = 'A' + (byteValue - 10);
- else
- loNibble = '0' + byteValue;
- *hexStr++ = hiNibble;
- *hexStr++ = loNibble;
- }
- HUnlock(han);
- *hexStr = '\0'; /* add terminator */
- } /* --------------------------------------- convertDataToHexStr */
-
- void convertFSSpecToStr(str, pSpec)
- /*
- Convert an FSSpec to a string.
- */
- char *str;
- FSSpecPtr pSpec;
- {
- char tempStr[256];
-
- *str = 0;
- addNumItemToList(str, pSpec->vRefNum);
- addNumItemToList(str, pSpec->parID);
- copyPtoCstr(tempStr, pSpec->name);
- addStrItemToList(str, tempStr);
- } /* --------------------------------------- convertFSSpecToStr */
-
- void convertHexStrToData(hexStr, hanReturn)
- /*
- Convert the ASCII hex characters
- to a handle of data.
-
- Handle is created in this function.
- */
- char *hexStr;
- Handle *hanReturn;
- {
- Handle han;
- Ptr pData;
- short lenHexStr;
- Size hanSize;
- Byte hiAsciiNibble,
- loAsciiNibble,
- dataValue;
-
- lenHexStr = strlen(hexStr);
- if(lenHexStr & 0x01)
- {
- DebugStr("\pconvertHexStrToData: hex string is odd length");
- *hanReturn = nil;
- return;
- }
- hanSize = lenHexStr >> 1; /* one-half */
- han = NewHandleClear(hanSize);
- if(han==nil || MemError())
- {
- DebugStr("\pconvertHexStrToData: NewHandleClear failed");
- *hanReturn = nil;
- return;
- }
- HLock(han);
- pData = *han;
- while(*hexStr)
- {
- hiAsciiNibble = *hexStr++;
- if(hiAsciiNibble>'9')
- dataValue = ((10 + hiAsciiNibble - 'A') << 4);
- else
- dataValue = (hiAsciiNibble - '0') << 4;
- loAsciiNibble = *hexStr++;
- if(loAsciiNibble>'9')
- dataValue |= 10 + loAsciiNibble - 'A';
- else
- dataValue |= loAsciiNibble - '0';
- *pData++ = dataValue;
- }
- HUnlock(han);
- *hanReturn = han;
- } /* --------------------------------------- convertHexStrToData */
-
- void convertStrToFSSpec(listStr, pSpec)
- /*
- Convert a string to an FSSpec.
- */
- char *listStr;
- FSSpecPtr pSpec;
- {
- char tempStr[256];
- long tempLong;
-
- getItemFromCList(listStr, 1, tempStr);
- StringToNum(c2pstr(tempStr), &tempLong);
- pSpec->vRefNum = tempLong;
- getItemFromCList(listStr, 2, tempStr);
- StringToNum(c2pstr(tempStr), &(pSpec->parID));
- getItemFromCList(listStr, 3, pSpec->name);
- } /* --------------------------------------- convertStrToFSSpec */
-
- void copyPtoCstr(Cstr, Pstr)
- /*
- Copy the Pstr to the Cstr.
- Don't do it in-place like ToCstr.
- */
- Str255 Pstr;
- char *Cstr;
- {
- short i;
-
- for(i=1; i<=Pstr[0]; i++)
- *Cstr++ = Pstr[i];
- *Cstr = 0;
- } /* --------------------------------------- copyPtoCstr */
-
- Handle copyStrToHand(str)
- /*
- Create a handle and copy the string to it.
- Return the handle.
- */
- char *str;
- {
- Handle newHndl;
-
- newHndl = (Handle) NewHandle((long) strlen(str) + 1);
- HLock(newHndl);
- strcpy(*newHndl, str);
- HUnlock(newHndl);
- return(newHndl);
- } /* -------------------------------------------- copyStrToHand */
-
- void deleteColon(volName)
- /*
- Delete a colon from the end of volName.
- If one isn't there, forget it.
- */
- Str255 volName;
- {
- if(volName[volName[0]]==kColon)
- volName[0]--;
- } /* -------------------------------------------- deleteColon */
-
- short equalPstr(s1, s2)
- /*
- Compare s1 and s2.
- If their contents are equal and they are of equal length, return TRUE.
- Comparison is not case-sensitive.
- */
- Str255 s1,
- s2;
- {
- short i,
- c1,
- c2;
-
- if(s1[0]!=s2[0])
- return false;
- for(i=1; i<=s1[0]; i++)
- {
- c1 = tolower(s1[i]);
- c2 = tolower(s2[i]);
- if(c1!=c2)
- return false;
- }
- return true;
- } /* -------------------------------------------- equalPstr */
-
- short findStrResId(resName)
- /*
- Given the name of a STR# resource, return
- its ID number. This lets us use names instead
- of ID's for tracking STR# resources.
- */
- char *resName;
- {
- Handle hRes;
- short theID;
- ResType theType;
- Str255 theName;
-
- strcpy(theName, resName);
- hRes = GetNamedResource('STR#', c2pstr(theName));
- if(!hRes || ResError())
- return 0;
- GetResInfo(hRes, &theID, &theType, theName);
- if(ResError()==resNotFound)
- return 0;
- else
- return theID;
- } /* -------------------------------------------- findStrResId */
-
- void getItemFromCList(itemListCstr, itemNum, itemCstr)
- /*
- Return the itemNum-th item in the itemListCstr.
- Stops at end of string or Return character (end of HyperCard line).
- Returns terminator if item not present.
- Does not return any punctuation (comma or return).
- */
- char *itemListCstr;
- short itemNum;
- char *itemCstr;
- {
- short itemCnt=1;
-
- /* Count commas to get itemNum-th item */
- while(itemCnt<itemNum && *itemListCstr!=0 && *itemListCstr!=kReturn)
- if(*itemListCstr++==kComma)
- itemCnt++;
- /* Copy itemNum-th item */
- /* skip leading spaces */
- if(itemCnt==itemNum)
- {
- while(*itemListCstr!=0 && *itemListCstr!=kReturn && *itemListCstr==kSpace)
- itemListCstr++;
- while(*itemListCstr!=0 && *itemListCstr!=kReturn && *itemListCstr!=kComma)
- *itemCstr++ = *itemListCstr++;
- }
- *itemCstr = kCterm;
-
- } /* -------------------------------------------- getItemFromCList */
-
- void getItemFromPList(itemListPstr, itemNum, itemPstr)
- /*
- Return the itemNum-th item in the itemListPstr
- */
- Str255 itemListPstr;
- short itemNum;
- Str255 itemPstr;
- {
- short i=1,
- j=0,
- itemCnt=1;
- /* Count commas to get itemNum-th item */
- while(itemCnt<itemNum && i<itemListPstr[0])
- if(itemListPstr[i++]==kComma)
- itemCnt++;
- /* Copy itemNum-th item */
- if(itemCnt==itemNum)
- while(i<=itemListPstr[0] && itemListPstr[i]!=kComma)
- itemPstr[++j] = itemListPstr[i++];
- itemPstr[0] = j;
- } /* -------------------------------------------- getItemFromPList */
-
- void handleToCstr(str, hndl)
- /*
- Return a copy of the string contained in the handle.
- If the handle is NIL, return an empty string.
- */
- char *str;
- Handle hndl;
- {
- if(hndl==nil)
- *str = kCterm;
- else
- {
- HLock(hndl);
- strcpy(str, *hndl);
- HUnlock(hndl);
- }
- } /* -------------------------------------------- handleToCstr */
-
- void handleToPstr(str, hndl)
- /*
- Return a copy of the string contained in the handle.
- If the handle is NIL, return an empty string.
- */
- Str255 str;
- Handle hndl;
- {
- if(hndl==nil)
- str[0] = 0;
- else
- {
- HLock(hndl);
- strcpy((char *)str, *hndl);
- HUnlock(hndl);
- c2pstr(str);
- }
- } /* -------------------------------------------- handleToPstr */
-
- void insertParent(pList, pParentToAdd, pSeparatorChar)
- /*
- Insert pParentToAdd and pSeparatorChar before pList.
-
- Note that pSeparatorChar is a C-string (has terminator.)
- */
- char *pList,
- *pParentToAdd,
- *pSeparatorChar;
- {
- char tempList[1024];
-
- strcpy(tempList, pParentToAdd);
- strcat(tempList, pSeparatorChar); /* add suffix following parent */
- strcat(tempList, pList); /* put list after new parent */
- strcpy(pList, tempList); /* copy back to list */
- } /* -------------------------------------------- insertParent */
-
- void pathNameFromFSSpec(Str255 pathName, FSSpec* fileSpec)
- /*
- Make the complete pathname from the FSSpec.
- Builds the full path by working it way up from the
- file name through all directories until it reaches the volume.
-
- pathNameFromFSSpec adapted from pathNameFromDirID by JRP.
- pathNameFromDirID converted from Pascal by JRP.
- Original Pascal courtesy of Skeptic and Cynic.
-
- 14-May-91 PBGetCatInfo returns "file not found" error
- after converting from Think to MPW.
- Reason was that Think automatically
- dereferenced CurDirStore to a long dirID.
-
- FSSpec* fileSpec; pass FSSpec
- Str255 pathName; return complete path name
- */
- {
- CInfoPBRec infoBlock;
- Str255 directoryStr;
- OSErr err=noErr;
- // Start with file name.
- PLstrcpy(pathName, fileSpec->name);
- directoryStr[0] = 0;
- infoBlock.dirInfo.ioCompletion = nil;
- infoBlock.dirInfo.ioNamePtr = (StringPtr) directoryStr;
- infoBlock.dirInfo.ioDrParID = fileSpec->parID;
- // Walk up the directory tree.
- do
- {
- infoBlock.dirInfo.ioVRefNum = fileSpec->vRefNum;
- infoBlock.dirInfo.ioFDirIndex = -1;
- infoBlock.dirInfo.ioDrDirID = infoBlock.dirInfo.ioDrParID;
- err = PBGetCatInfo(&infoBlock, false);
- PLstrcat(directoryStr, "\p:");
- PLstrcat(directoryStr, pathName);
- PLstrcpy(pathName, directoryStr);
- }
- while(err==noErr && infoBlock.dirInfo.ioDrDirID!=2);
- } /* end pathNameFromDirID ---------------- */
-
- void returnMsgNum(paramPtr, strNum, strResId, num)
- /*
- Given the STR# number and a number,
- place the string and the number
- in the return to HyperCard.
- The num is optional, if 0 then it is not placed.
-
- 11-16-90 1.0d4 JRP add strResId as a parameter
- */
- XCmdPtr paramPtr; /* the HyperCard connection */
- short strNum,
- strResId;
- long num;
- {
- Str255 resPstr;
- char resultStr[256];
-
- GetIndString(resPstr, strResId, strNum);
- strcpy(resultStr, p2cstr(resPstr));
- if(num!=kNoErrNum)
- addNumItemToList(resultStr, num);
- paramPtr->returnValue = copyStrToHand(resultStr);
- } /* -------------------------------------------- returnMsgNum */
-
-